package com.zhkj.lib.utils

import com.google.gson.Gson
import java.lang.Exception

object AccountManager {
    private val TOKEN = "token"
    private val ID = "id"
    private val AVATAR = "avatar"
    private val NICKNAME = "nickName"
    private val IS_MEMBER = "member"
    private val CHAT_ID = "chatId"
    val SHOP_ID = "SHOP_ID"
    val SHOP_INFO = "sHOP_INFO"

    fun saveToken(token: String) {
        SPUtil.getInstance()
            .putString(TOKEN, token)
    }

    fun getToken(): String = SPUtil.getInstance()
        .getString(TOKEN) ?: ""

    fun saveUserId(id: Long) {
        SPUtil.getInstance()
            .putLong(ID, id)
    }

    fun saveAvatar(avatar: String) {
        SPUtil.getInstance().putString(AVATAR, avatar)
    }

    fun saveMemberStatus(isMember: Boolean) {
        SPUtil.getInstance().putBoolean(IS_MEMBER, isMember)
    }

    fun saveNickname(nickname: String) {
        SPUtil.getInstance().putString(NICKNAME, nickname)
    }

    fun saveChatId(chatId: String) {
        SPUtil.getInstance().putString(CHAT_ID, chatId)
    }

    fun getChatId() = SPUtil.getInstance().getString(CHAT_ID)?:""

    fun getUserId(): Long = SPUtil.getInstance().getLong(ID, 0)

    fun getAvatar(): String = SPUtil.getInstance().getString(AVATAR) ?: ""
    fun getNickname(): String = SPUtil.getInstance().getString(NICKNAME) ?: ""
    fun isMember() = SPUtil.getInstance().getBoolean(IS_MEMBER, false)

    fun clearUserInfo() {
        SPUtil.getInstance().clear()
    }
}